package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.entity.Product;
import com.project.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "商品接口")
@RequestMapping("product")
public class ProductController {
    @Autowired
    private ProductService productService;
    @ApiOperation(value = "动态条件分页查询商品集合")
    @GetMapping("cutByItem/{pageNum}")
    public IPage<Product> cutByItem(@PathVariable("pageNum") Integer pageNum, String productName, Integer startStoreNum, String type, Integer endStoreNum) {
        return productService.cutByItem(pageNum, productName, startStoreNum, type, endStoreNum);
    }

    @ApiOperation(value = "按ID查询商品详情信息")
    @GetMapping("findProductInfoById/{productId}")
    public Product findProductInfoById(@PathVariable("productId") Integer productId) {
        return productService.findProductInfoById(productId);
    }

    @ApiOperation(value = "修改销售价")
    @PutMapping("updateSellPrice")
    public String updateSellPrice(Integer productId, Integer newSellPrice) {
        productService.updateSellPrice(productId, newSellPrice);
        return "ok";
    }
}
